﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesFile;

namespace ISchool
{
    class IOpenDocment
    {
        //作者：代兴梅
        //打开：地图文档
        private AxMapControl m_MapControl;
        
        public  IMapDocument m_MapDocment;

        public IOpenDocment(AxMapControl test)
        {
            m_MapControl = test;
        }
        /// <summary>
        /// 打开地图文档
        /// </summary>
        public void mOpen()
        {
            string fileName = "";
            m_MapDocment = new MapDocumentClass();
            OpenFileDialog addData = new OpenFileDialog();
            addData.InitialDirectory = "c:\\";
            addData.Filter = "mxd|*.mxd";
            addData.RestoreDirectory = true;
            addData.FilterIndex = 1;
            if (addData.ShowDialog() == DialogResult.OK)
            {
                fileName = addData.FileName;
                if (this.m_MapControl.CheckMxFile(fileName) == false)
                {
                    MessageBox.Show("文件无法打开");
                }
                else
                {
                    if (!isEmpty())
                        m_MapControl.Map.ClearLayers();
                    this.m_MapControl.LoadMxFile(fileName);
                    this.m_MapControl.Extent = this.m_MapControl.FullExtent;

                    m_MapDocment.Open(fileName, "");
                    this.m_MapControl.Map = m_MapDocment.get_Map(0);
                }
            }
        }
        /// <summary>
        /// 获取当前地图的地图数量
        /// </summary>
        public int mMapNum 
        {
            get {
                return m_MapControl.Map.LayerCount;
            }
        }
        public bool isEmpty()
        {
            if (m_MapControl.Map.LayerCount > 0) return false;
            else
            return true;
        }
    }
}
